
#include "aos/hal/flash.h"
#include <aos/kernel.h>

/****************************************************************************************************
 *        spi nor flash partition  (begin addr :0x60000000, total: 0x400000 4M bytes)               *
 * off: 0x0    0x18000     118000 200000   300000    3C8000  3E0000 3FC000 3FD000 3FE000 0x400000   *
 *      |   96k    |  1024k  | 928k |  1024k |   800k   | 96k  | 112k |  4k | 4K  |  8K |           *
 *      |==========|=========|======|========|==========|======|======|=====|=====|=====|           *
 *       bootloader    app     resv  otabackup subdevice  resv    KV     P1   P3    p4*             *
 *                                                                                                  *
 * Note: 1. Do not change the bootloader partition start address and size                           *
 *       2. Do not change the application partition start address                                   *
 *       3. Do not change the ota backup partition start address                                    *
 ****************************************************************************************************/


/* Logic partition on flash devices */
hal_logic_partition_t hal_partitions[HAL_PARTITION_MAX];

void board_flash_partition_init(void)
{
    hal_partitions[HAL_PARTITION_BOOTLOADER].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_BOOTLOADER].partition_description      = "Bootloader";
    hal_partitions[HAL_PARTITION_BOOTLOADER].partition_start_addr       = 0x60000000;
    hal_partitions[HAL_PARTITION_BOOTLOADER].partition_length           = 0x00030000;        /* 192k bytes */
    hal_partitions[HAL_PARTITION_BOOTLOADER].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_APPLICATION].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_APPLICATION].partition_description      = "Application";
    hal_partitions[HAL_PARTITION_APPLICATION].partition_start_addr       = 0x60030000;
    hal_partitions[HAL_PARTITION_APPLICATION].partition_length           = 0x00100000;       /* 1M bytes */
    hal_partitions[HAL_PARTITION_APPLICATION].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_OTA_TEMP].partition_owner               = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_OTA_TEMP].partition_description         = "OTA Storage";   /* used for OTA backup APP */
    hal_partitions[HAL_PARTITION_OTA_TEMP].partition_start_addr          = 0x60188000;
    hal_partitions[HAL_PARTITION_OTA_TEMP].partition_length              = 0x00100000;       /* 1024 Kbytes */
    hal_partitions[HAL_PARTITION_OTA_TEMP].partition_options             = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_OTA_SUB].partition_owner                = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_OTA_SUB].partition_description          = "OTA SUB devices"; /* used for OTA Subdevices */
    hal_partitions[HAL_PARTITION_OTA_SUB].partition_start_addr           = 0x602EC000;
    hal_partitions[HAL_PARTITION_OTA_SUB].partition_length               = 0x00100000;       /* 1024 Kbytes */
    hal_partitions[HAL_PARTITION_OTA_SUB].partition_options              = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_PARAMETER_2].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_PARAMETER_2].partition_description      = "PARAMETER2";     /* used for kv */
    hal_partitions[HAL_PARTITION_PARAMETER_2].partition_start_addr       = 0x603EC000;
    hal_partitions[HAL_PARTITION_PARAMETER_2].partition_length           = 0x00010000;       /* 64k bytes */
    hal_partitions[HAL_PARTITION_PARAMETER_2].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_PARAMETER_1].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_PARAMETER_1].partition_description      = "PARAMETER1";     /* used for OTA param */
    hal_partitions[HAL_PARTITION_PARAMETER_1].partition_start_addr       = 0x603FC000;
    hal_partitions[HAL_PARTITION_PARAMETER_1].partition_length           = 0x00001000;       /* 4k bytes */
    hal_partitions[HAL_PARTITION_PARAMETER_1].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;
    
    hal_partitions[HAL_PARTITION_PARAMETER_3].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_PARAMETER_3].partition_description      = "PARAMETER3";    /* reserved */
    hal_partitions[HAL_PARTITION_PARAMETER_3].partition_start_addr       = 0x603FD000;
    hal_partitions[HAL_PARTITION_PARAMETER_3].partition_length           = 0x00001000;      /* 4k bytes */
    hal_partitions[HAL_PARTITION_PARAMETER_3].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    hal_partitions[HAL_PARTITION_PARAMETER_4].partition_owner            = HAL_FLASH_QSPI;
    hal_partitions[HAL_PARTITION_PARAMETER_4].partition_description      = "PARAMETER4";   /* used for security */
    hal_partitions[HAL_PARTITION_PARAMETER_4].partition_start_addr       = 0x603FE000;
    hal_partitions[HAL_PARTITION_PARAMETER_4].partition_length           = 0x00002000;     /* 8k bytes */
    hal_partitions[HAL_PARTITION_PARAMETER_4].partition_options          = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN;

    return ;

}